home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Orlando_1993 / Devcon93.1 / AREXX / ttx / ASCII2AG.ttx
Encoding:
Text File  |  1993-01-11  |  6.1 KB  |  245 lines

  1. /**********************************************************
  2.  
  3.         (c) Copyright 1992-93 Commodore-Amiga, Inc.
  4.                    All rights reserved.
  5.  
  6. This software is provided as-is and is subject to change;
  7. no warranties are made.  All use is at your own risk.  No
  8. liability or responsibility is assumed.
  9.  
  10.  
  11.               $VER: ASCII2AG.ttx 1.00 (07.01.93)
  12.             ----------------------------------
  13.       Make an ASCII file into an AmigaGuide database.
  14.           File must specify where nodes start by:
  15.  
  16.              <node#>@<node name> <node title>
  17.  
  18.                  Written by Jerry Hartzler
  19.  
  20. **********************************************************/
  21.  
  22. options results
  23.  
  24. setinputlock on
  25. getport                        /* Get some file information */
  26. workport=result
  27. getfilepath
  28. file=result
  29. getfileinfo
  30. parse var result . . filename
  31. filename=compress(filename,'" ')
  32.  
  33. getprefs findbackward              /* Save User prefs and */
  34. fbw=result                          /* setup program prefs */
  35. getprefs findignorecase
  36. fic=result
  37. getprefs findstring
  38. fs=result
  39. getprefs findwholewords
  40. fww=result
  41. setprefs findbackward off
  42. setprefs findignorecase on
  43. setprefs findwholewords off
  44.  
  45. /**********************************************************
  46.        Check work file for correct node formatting
  47. **********************************************************/
  48.  
  49. err=0
  50. SetStatusBar Temporary 'Error Checking...'
  51. movesof
  52. insertline
  53. moveup
  54. lchar=0
  55.  
  56. movesof                     /* Check if there are any nodes */
  57. find '?@'
  58. if rc~=0 then do
  59.     message='"No nodes found!"'
  60.     call error1
  61.     end
  62.  
  63. else do                   /* Check if 1st node is MAIN (0@) */
  64.     getchar
  65.     if result~=0 then do
  66.         message='"First section tag is not 0@"'
  67.         call error1
  68.         end
  69.  
  70.     find '0@'      /* Check if more MAIN nodes are found */
  71.     if rc=0 then do
  72.         message='File must have only one 0@'
  73.         call error2
  74.         end
  75.     end
  76.  
  77. do forever      /* Check if Nodes are in squential order */
  78.     find '?@'
  79.     if rc~=0 then break
  80.     call position
  81.     llin=lin
  82.     if col=1 then do
  83.         getchar
  84.         char=result
  85.         test=datatype(char)
  86.         if test='NUM' then do
  87.             if char<lchar then lchar=char
  88.             if lchar~=char & lchar+1~=char then do
  89.                 message='Section numbers not in sequentual order'
  90.                 call error2
  91.                 end
  92.             lchar=char
  93.             end
  94.  
  95.         moveright 2              /* Check if two nodes   */
  96.         getchar                  /* have identical names */
  97.         nchar=C2D(result)
  98.         if nchar~=32 & nchar~=10 then do
  99.             setprefs findignorecase off
  100.             setprefs findwholewords on
  101.             setbookmark 1
  102.             getword
  103.             fword='?'substr(result,2)
  104.             do forever
  105.                 find fword
  106.                 if rc~=0 then break
  107.                 call position
  108.                 if col=1 then do
  109.                     message='Same NODE names: lines' llin-1 '&' lin-1
  110.                     call error2
  111.                     end
  112.                 end
  113.             setprefs findignorecase on
  114.             setprefs findwholewords off
  115.             movebookmark 1
  116.             end
  117.         end
  118.     end
  119.  
  120. /**********************************************************
  121.           Format work file as AmigaGuide database
  122. **********************************************************/
  123.  
  124. movesof                    /* Make work file an AG database */
  125. text '@DATABASE'
  126.  
  127. if stnode=1 then do             /* Insert MAIN (0@) node */
  128.     insertline                  /* if one does not exist */
  129.     text '0@'
  130.     movesof
  131.     end
  132.  
  133. nodenum=0
  134. endnum=0
  135. lchar=1
  136. do forever
  137.     node=''
  138.     find '?@'
  139.     if rc~=0 then leave     /* exit when ?@ is not found */
  140.  
  141.     getcursorpos         /* does ?@ start on 1st column? */
  142.     parse var result . col .
  143.  
  144.     if col=1 then do
  145.         getchar
  146.         char=result
  147.  
  148.         if char=0 then do          /* 0@ is the MAIN node */
  149.             node='MAIN'
  150.             end
  151.  
  152.         else do                  /* every NODE must have */
  153.             text '@ENDNODE'      /* an ENDNODE           */
  154.             insertline
  155.             end
  156.  
  157.         delete
  158.         getline 2
  159.         line=result             /* Call to parse ?@ line */
  160.         call nodename           /* for any NODE info     */
  161.         moveright 1
  162.         deleteeol
  163.         text 'NODE' node name               /* Make NODE */
  164.         movesol
  165.         test=datatype(char)
  166.  
  167.         if char~=0 & test='NUM' then do
  168.             moveup                      /* Make Link Point */
  169.             setbookmark endnum        /* for NODE        */
  170.             movebookmark char-1
  171.             if strip(name,'b','"')='' then name=node
  172.             text '@{'name 'link' node'}' /* ^if no title */
  173.             insertline               /* use name of NODE */
  174.             setbookmark char-1
  175.             movebookmark endnum
  176.             movedown
  177.             endnum=char
  178.             end
  179.         end
  180.     end
  181.  
  182. moveeof
  183. text '@ENDNODE'        /* Insert ENDNODE at end of database */
  184. insertline
  185. call quit
  186.  
  187. /**********************************************************
  188.                           Calls
  189. **********************************************************/
  190.  
  191.  
  192. nodename:                 /* Parse ?@ line for NODE info */
  193.     name=''
  194.     if length(line)>0 then do
  195.         if C2D(left(line,1))~=32 & node='' then do
  196.             node='"'subword(line,1,1)'"' /* Get NODE name */
  197.             line=subword(line,2)
  198.             end
  199.         if length(line)>0 then name='"'strip(line,'b','" ')'"'
  200.         else name=''                  /* ^Get NODE title */
  201.         end
  202.     if node='' then do            /* If NODE has no name */
  203.         nodenum=nodenum+1         /* make one up         */
  204.         node='"'filename'_'nodenum'"'
  205.         end
  206.     return
  207.  
  208.  
  209. position:                         /* Find column position */
  210.     getcursorpos
  211.     parse var result lin col .
  212.     return
  213.  
  214.  
  215. error1:               /* Does user want a MAIN (?@) node */
  216.     requestbool TITLE message PROMPT '"Make One?  OK=Yes CANCEL=No"'
  217.     if result='NO' then call error2
  218.     stnode=1
  219.     return
  220.  
  221.  
  222. error2:            /* Change work file to the way it was */
  223.     err=1
  224.     setbookmark 1
  225.     movesof
  226.     delete
  227.     movebookmark 1
  228.     beepscreen
  229.     SetStatusBar message
  230.     call quit
  231.  
  232.  
  233. quit:                                         /* Bye Bye */
  234.     address value workport     /* Set back to user Prefs */
  235.     setprefs findbackward fbw
  236.     setprefs findignorecase fic
  237.     setprefs findstring fs
  238.     setprefs findwholewords fww
  239.     setinputlock off
  240.     if err=0 then do
  241.         movesof
  242.         SetStatusBar 'Operation Complete'
  243.         end
  244.     exit
  245.